/**
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * <p>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package io.gitee.huangjianbo.supos.openapi.core.http.request.types;

import com.alibaba.fastjson2.JSON;

import io.gitee.huangjianbo.supos.openapi.core.http.HttpHeader;
import io.gitee.huangjianbo.supos.openapi.core.http.HttpPath;
import io.gitee.huangjianbo.supos.openapi.core.http.request.MultipartFormDataPair;
import io.gitee.huangjianbo.supos.openapi.core.http.request.RequestArguments;

import java.util.*;
import java.util.function.Consumer;
import java.util.function.Predicate;
import java.util.stream.Stream;

/**
 * Set包装类
 *
 * @author tomcat
 * @version 1.0
 */
public final class RSet<E extends RequestArguments> implements Set<E>, RequestArguments {
    private static final long serialVersionUID = -6511620453315504798L;

    private final Set<E> data = new HashSet<>();

    @Override
    public void forEach(Consumer<? super E> action) {
        data.forEach(action);
    }

    @Override
    public boolean removeIf(Predicate<? super E> filter) {
        return data.removeIf(filter);
    }

    @Override
    public Stream<E> stream() {
        return data.stream();
    }

    @Override
    public Stream<E> parallelStream() {
        return data.parallelStream();
    }

    @Override
    public boolean validate() {
        if (!data.isEmpty()) {
            for (E e : data) {
                if (!e.validate()) {
                    return false;
                }
            }
        }
        return true;
    }

    @Override
    public String toQueryString() {
        return "";
    }

    @Override
    public HttpHeader toHeader() {
        return HttpHeader.of();
    }

    @Override
    public String toBodyJsonString() {
        return JSON.toJSONString(data);
    }

    @Override
    public HttpPath toHttpPath(HttpPath definePath) {
        return definePath;
    }

    @Override
    public List<MultipartFormDataPair> toMultipartFormData() {
        return new ArrayList<>();
    }

    @Override
    public int size() {
        return data.size();
    }

    @Override
    public boolean isEmpty() {
        return data.isEmpty();
    }

    @Override
    public boolean contains(Object o) {
        return data.contains(o);
    }

    @Override
    public Iterator<E> iterator() {
        return data.iterator();
    }

    @Override
    public Object[] toArray() {
        return data.toArray();
    }

    @Override
    public <T> T[] toArray(T[] a) {
        return data.toArray(a);
    }

    @Override
    public boolean add(E e) {
        return data.add(e);
    }

    @Override
    public boolean remove(Object o) {
        return data.remove(o);
    }

    @Override
    public boolean containsAll(Collection<?> c) {
        return data.containsAll(c);
    }

    @Override
    public boolean addAll(Collection<? extends E> c) {
        return data.addAll(c);
    }

    @Override
    public boolean retainAll(Collection<?> c) {
        return data.retainAll(c);
    }

    @Override
    public boolean removeAll(Collection<?> c) {
        return data.removeAll(c);
    }

    @Override
    public void clear() {
        data.clear();
    }

    @Override
    public Spliterator<E> spliterator() {
        return data.spliterator();
    }
}
